package template

var TABLE_RELATION_RESOLVER_GO = `

{{range .Params.RelationMaps}}
func (r *{{$.Params.ResolverImplTypeName}}) {{.FunctionName}}(ctx context.Context, obj *model1.{{.ParamTypeName}}) (*model1.{{.ReturnTypeName}}, error) {
	{{if .Column.Nullable}}
	if obj.{{.DataloaderColumn}} == nil{
		return nil, nil
	}
	{{end}}
	var loader model1.{{.DataloaderName}}
	i := dataloader.GetLoaders(ctx).GetLoader(&loader, ctx)
	switch t := i.(type) {
	case *model1.{{.DataloaderName}}:
		{{if .Column.Nullable}}
		return t.Load(*obj.{{.DataloaderColumn}})
		{{else}}
		return t.Load(obj.{{.DataloaderColumn}})
		{{end}}
		
	default:
		panic("can not get dataloader")
	}
}
{{end}}

// Department returns generated.DepartmentResolver implementation.
func (r *Resolver) {{.Params.ResolverImplFuncName}}() generated.{{.Params.ResolverInterfaceName}} { return &{{.Params.ResolverImplTypeName}} {r} }

type {{.Params.ResolverImplTypeName}} struct{ *Resolver }
`
